#include "command.h"
#include "string.h"
#define  NUM   2

/*
    // 结构体变量初始化方式1
    command_t  cmd_arr = 
        {"led1on",GPIOE,GPIO_PIN_10,GPIO_SET,hal_gpio_write};
    // 结构体变量初始化方式2
    cmd_arr.cmd_str = "led1on";
    cmd_arr.gpios = GPIOE;
    cmd_arr.pins = GPIO_PIN_10;
    cmd_arr.state = GPIO_SET;
    cmd_arr.hal_gpio_write_p = hal_gpio_write;
    // 结构体变量初始化方式3
    command_t  cmd_arr  = {
        .cmd_str = "led1on",
        .gpios = GPIOE,
        .pins = GPIO_PIN_10,
        .state = GPIO_SET,
        .hal_gpio_write_p = hal_gpio_write,
    };

    command_t  cmd_arr[2] = {
        {"led1on",GPIOE,GPIO_PIN_10,GPIO_SET,hal_gpio_write},
        {"led1off",GPIOE,GPIO_PIN_10,GPIO_RESET,hal_gpio_write}
    };
    cmd_arr[0].cmd_str = "led1on";
    cmd_arr[0].gpios = GPIOE;
    cmd_arr[0].pins = GPIO_PIN_10;
    cmd_arr[0].state = GPIO_SET;
    cmd_arr[0].hal_gpio_write_p = hal_gpio_write;
    cmd_arr[1].cmd_str = "led1off";
    cmd_arr[1].gpios = GPIOE;
    cmd_arr[1].pins = GPIO_PIN_10;
    cmd_arr[1].state = GPIO_RESET;
    cmd_arr[1].hal_gpio_write_p = hal_gpio_write;

    command_t  cmd_arr[NUM]  = {
    [0] = {
        .cmd_str = "led1on",
        .gpios = GPIOE,
        .pins = GPIO_PIN_10,
        .state = GPIO_SET,
        .hal_gpio_write_p = hal_gpio_write,
    }, 
    [1] = {
        .cmd_str = "led1off",
        .gpios = GPIOE,
        .pins = GPIO_PIN_10,
        .state = GPIO_RESET,
        .hal_gpio_write_p = hal_gpio_write,
    }
};

*/

command_t  cmd_arr[NUM]  = {
    [0] = {
        .cmd_str = "led1on",
        .gpios = GPIOE,
        .pins = GPIO_PIN_10,
        .state = GPIO_SET,
        .hal_gpio_write_p = hal_gpio_write,
    }, 
    [1] = {
        .cmd_str = "led1off",
        .gpios = GPIOE,
        .pins = GPIO_PIN_10,
        .state = GPIO_RESET,
        .hal_gpio_write_p = hal_gpio_write,
    }
};

command_t * find_command(const char *uart_str)
{
    unsigned int i;
    for (i = 0; i < NUM;i++)
    {
        if (!strcmp(uart_str, cmd_arr[i].cmd_str))
        {
            return &cmd_arr[i];
        }
    }
    return 0;
}